CSharpTest.Net
Replace Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > SetList<T> Class : Replace Method

item

Glossary Item Box

Adds or replaces an item in the collection, returns true if an entry was replaced

Syntax

Visual Basic (Declaration) 
Public Function Replace( _
   ByVal item As T _
) As Boolean
C# 
public bool Replace( 
   T item
)

Parameters

item

Example

Library/Library.Test/TestSetList.cs

C#Copy Code
MyValue one = new MyValue(1);
MyValue two = new MyValue(2);
SetList<MyValue> set = new SetList<MyValue>();
set.Add(one);
set.Add(two);

Assert.IsTrue(Object.ReferenceEquals(one, set[0]));
Assert.IsTrue(set.Replace(new MyValue(1)));
Assert.IsFalse(Object.ReferenceEquals(one, set[0]));

Assert.AreEqual(2, set.Count);
Assert.IsFalse(set.Replace(new MyValue(3))); //not replaced, then added
Assert.AreEqual(3, set.Count);
VB.NETCopy Code
Dim one As New MyValue(1)
Dim two As New MyValue(2)
Dim [set] As New SetList(Of MyValue)()
[set].Add(one)
[set].Add(two)

Assert.IsTrue([Object].ReferenceEquals(one, [set](0)))
Assert.IsTrue([set].Replace(New MyValue(1)))
Assert.IsFalse([Object].ReferenceEquals(one, [set](0)))

Assert.AreEqual(2, [set].Count)
Assert.IsFalse([set].Replace(New MyValue(3)))
'not replaced, then added
Assert.AreEqual(3, [set].Count)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys